<?php


class News extends Base_Controller
{
	
	public function __construct()
	{
		parent::__construct();
		$this->load->model( 'news_mdl', 'news' );
	}
	
	public function index()
	{
				/*分页设置*/
		$enabled = intval($this->uri->rsegment(4));
		$page = $this->uri->rsegment(4);
	
		$page = ($page && is_numeric($page)) ? intval($page) : 1;
		$limit = 10;
		$offset = ($page - 1) * $limit;
		$pagination = '';
		
		$count = $this->news->getNewCount();
		$this->load->library('pagination');
		$config['base_url'] = base_url().'/news/index/page/';
		$config['total_rows'] = $count;
		//设置url上第几段用于传递分页器的偏移量
		$config ['uri_segment'] = 4;	 
		$config['per_page'] = $limit; 
		$config['use_page_numbers'] = TRUE;
		$this->pagination->initialize($config); 
				
		$data = array();
		$data['list'] = $this->news->getNewsList( true,$limit, $offset,'DESC' );
		$data['page'] = $this->pagination->create_links();
		
		//分类
		$this->load->model( 'zixuncategory_mdl', 'zixuncategory' );
		$category = $this->zixuncategory->getZixunCategoryList( false );
		$data['zixuncategory'] = $category;
		
		$this->load->view( 'news', $data );
	}
	
	public function view()
	{
		$id = intval( $this->uri->rsegment(3) );
		$zixun = array();
		$zixun = $this->news->getZixunById( $id );
	
		$data['zixun'] = $zixun;
		
		$this->load->view( 'new_view', $data);
	}
}